org.piratis.j2me.core.game
Class LayerManager

java.lang.Object
  extended byorg.piratis.j2me.core.game.LayerManager

public class LayerManager
extends java.lang.Object

As in MIDP2.0, the LayerManager manages Layers. The LayerManager simplifies the process of rendering the Layers that have been added to it by automatically rendering the correct regions of each Layer in the appropriate order.

The LayerManager mantains an ordered list to which Layers can be appended, inserted and removed. Its index in the list correlates to its z-order: index 0 is closest to the user, while the higher index, the further from the user. TODO: is it necessary to keep an own bbox?

Version:
$Id: LayerManager.java,v 1.3 2004/06/26 18:48:31 piratis Exp $
Author:
Jordi Martín

Constructor Summary
LayerManager()
          Creates a new LayerManager
 
Method Summary
 void add(Layer l)
          Appends a Layer to this LayerManager.
 Layer getLayerAt(int idx)
          Gets the layer at the specified index
 int getSize()
          Gets the number of layers
 BBox2D getWindow()
          Retrieve the current world window
 void insertAt(Layer l, int idx)
          Inserts a Layer at a given position.
 void paint(Graphics g, int x, int y)
          Renders the LayerManager's Layers.
 void remove(Layer l)
          Deletes the Layer from this LayerManager.
 void setWindow(BBox2D other)
          Sets the view window on the LayerManager
 void setWindow(int x, int y, int width, int height)
          Sets the view window on the LayerManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LayerManager

public LayerManager()
Creates a new LayerManager

Method Detail

add

public void add(Layer l)
Appends a Layer to this LayerManager. It will be given the highest position available, thus the furthest away from the user. It is also first removed if was previously added

Parameters:
l -

insertAt

public void insertAt(Layer l,
                     int idx)
Inserts a Layer at a given position. The Layer is first removed if previously added, and Layers with index equals or greater than the specified are shift to the right.

Parameters:
l - Layer
idx - where to insert the layer

getLayerAt

public Layer getLayerAt(int idx)
Gets the layer at the specified index

Parameters:
idx - the index
Returns:
the Layer, if index ok
Throws:
java.lang.IndexOutOfBoundsException - if element not found at the specified index

getSize

public int getSize()
Gets the number of layers

Returns:
the number of layers

remove

public void remove(Layer l)
Deletes the Layer from this LayerManager.

Parameters:
l - the Layer to be removed

paint

public void paint(Graphics g,
                  int x,
                  int y)
Renders the LayerManager's Layers.

The Layers within this LayerManager are rendered following the z-order given by its position, i.e. descending order.

x,y params specify where is the LayerManager to be rendered relative to the Graphic's origin.

Parameters:
g - to draw the LayerManager
x - horizontal location at which to render the view window
y - vertical location at which to render the view window
See Also:
setWindow(int, int, int, int)

setWindow

public void setWindow(int x,
                      int y,
                      int width,
                      int height)
Sets the view window on the LayerManager.

Parameters:
x - left relative to the LayerManager's origin
y - top idem.
width -
height -

setWindow

public void setWindow(BBox2D other)
Sets the view window on the LayerManager

Parameters:
other - the new view window
See Also:
setWindow(int, int, int, int)

getWindow

public BBox2D getWindow()
Retrieve the current world window

Returns:
world's window

Copyright(c) 2003-2004 Jordi Martin